home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / c / ObjectiveGT1_0.lha / Examples / Manx / viewfile.c < prev   
C/C++ Source or Header  |  1992-10-21  |  10KB  |  310 lines

  1. /*
  2. ** $Filename: viewfile.c $
  3. ** $Release : 1.0        $
  4. ** $Revision: 1.280      $
  5. ** $Date    : 21/10/92   $
  6. **
  7. **
  8. ** (C) Copyright 1992 Davide Massarenti
  9. **              All Rights Reserved
  10. **
  11. ** MANX 5.2: cc -ps -wdrunpo -so <name>.c
  12. **           ln -o <name> <name>.o -lOGTglue -lc16
  13. **
  14. */
  15.  
  16. #include <OGT/ObjectiveGadTools.h>
  17.  
  18. #define ARGS_TEMPLATE "FILE/K,FONT/K,SIZE/N"
  19. #define ARGS_FILE       (0)
  20. #define ARGS_FONT       (1)
  21. #define ARGS_SIZE       (2)
  22. #define ARGS_NUMOF      (3)
  23.  
  24. static LONG args[ ARGS_NUMOF ];
  25.  
  26. #define GADGETID_SHOWLIST  (1)
  27.  
  28. static char Class_AslReq  [] =   ASLREQ_OGT_CLASS;
  29. static char Class_Scroller[] = SCROLLER_OGT_CLASS;
  30. static char Class_Showlist[] = SHOWLIST_OGT_CLASS;
  31.  
  32. struct TextAttr   MyAttr = { NULL, 8 };
  33. struct TextFont  *MyFont;
  34.  
  35. APTR              VInfo;
  36. struct Window    *Win;
  37. Object          **Gads;
  38. struct RDArgs    *Ra;
  39.  
  40. struct IBox zoom = { 0, 0, 80, 30 };
  41.  
  42. struct TagItem WindowDescTags[] =
  43. {
  44.    { OVI_GimmeZeroZero    , TRUE                                  },
  45.    { OVI_AdaptWidthToFont , TRUE                                  },
  46.    { OVI_AdaptHeightToFont, TRUE                                  },
  47.    { OGT_ScaleLeft        , OGT_FontRelative                      },
  48.    { OGT_ScaleTop         , OGT_FontRelative                      },
  49.    { OGT_ScaleWidth       , OGT_FontRelative                      },
  50.    { OGT_ScaleHeight      , OGT_FontRelative                      },
  51.    { OGT_DomainXscale     , ~0                                    },
  52.    { OGT_DomainYscale     , ~0                                    },
  53.    { WA_Title             , "ViewFile"                            },
  54.    { WA_Activate          , TRUE                                  },
  55.    { WA_SmartRefresh      , TRUE                                  },
  56.    { WA_NoCareRefresh     , TRUE                                  },
  57.    { WA_DepthGadget       , TRUE                                  },
  58.    { WA_SizeGadget        , TRUE                                  },
  59.    { WA_SizeBBottom       , TRUE                                  },
  60.    { WA_SizeBRight        , TRUE                                  },
  61.    { WA_DragBar           , TRUE                                  },
  62.    { WA_Left              , 400                                   },
  63.    { WA_Top               , 150                                   },
  64.    { WA_InnerWidth        , 306                                   },
  65.    { WA_InnerHeight       , 120                                   },
  66.    { WA_MinWidth          , 80                                    },
  67.    { WA_MinHeight         , 20                                    },
  68.    { WA_MaxWidth          , 306                                   },
  69.    { WA_MaxHeight         , 140                                   },
  70.    { WA_Zoom              , &zoom                                 },
  71.    { WA_IDCMP             , IDCMP_CLOSEWINDOW | IDCMP_IDCMPUPDATE },
  72.    { WA_CloseGadget       , TRUE                                  },
  73.    { TAG_DONE                                                     }
  74. };
  75.  
  76.  
  77. struct TagItem Object1Desc[] = /* ASLREQ_OGT_CLASS */
  78. {
  79.    { OGT_SetDimReference, OGT_X_Dim_Relative },
  80.    { OGT_SetPosHandle   , OGT_Y_Bottom       },
  81.    { GA_RelBottom       , 0                  },
  82.    { GA_Height          , 14                 },
  83.  
  84.    { GA_Text            , "_F"               },
  85.    { OGT_TextPlacement  , OGT_Text_HIDE      },
  86.  
  87.    { OGTAR_Type         , ASL_FileRequest    },
  88.    { OGTAR_ShowSelected , TRUE               },
  89.    { TAG_DONE                                }
  90. };
  91.  
  92. struct TagItem Object1Post[] =
  93. {
  94.    { OGTAR_FullFileName },
  95.    { TAG_DONE           }
  96. };
  97.  
  98.  
  99. struct TagItem Object2Desc[] = /* SCROLLER_OGT_CLASS */
  100. {
  101.    { GA_Immediate       , TRUE                                    },
  102.    { GA_FollowMouse     , TRUE                                    },
  103.    { GA_RelVerify       , TRUE                                    },
  104.    { ICA_TARGET         , NULL                                    },
  105.  
  106.    { OGT_SetDimReference, OGT_X_Dim_Relative | OGT_Y_Dim_Relative },
  107.    { GA_RightBorder     , TRUE                                    },
  108.  
  109.    { PGA_Freedom        , FREEVERT                                },
  110.    { TAG_DONE                                                     }
  111. };
  112.  
  113.  
  114. struct TagItem Object3Desc[] = /* SCROLLER_OGT_CLASS */
  115. {
  116.    { GA_Immediate       , TRUE                                    },
  117.    { GA_FollowMouse     , TRUE                                    },
  118.    { GA_RelVerify       , TRUE                                    },
  119.    { ICA_TARGET         , NULL                                    },
  120.  
  121.    { OGT_SetDimReference, OGT_X_Dim_Relative | OGT_Y_Dim_Relative },
  122.    { GA_BottomBorder    , TRUE                                    },
  123.  
  124.    { PGA_Freedom        , FREEHORIZ                               },
  125.    { TAG_DONE                                                     }
  126. };
  127.  
  128.  
  129. struct TagItem Object4Desc[] = /* SHOWLIST_OGT_CLASS */
  130. {
  131.    { GA_ID              , GADGETID_SHOWLIST                     },
  132.    { OGT_AppGadget      , TRUE                                  },
  133.    { GA_Immediate       , TRUE                                  },
  134.    { GA_FollowMouse     , TRUE                                  },
  135.    { GA_RelVerify       , TRUE                                  },
  136.  
  137.    { OGT_SetDimReference, OGT_X_Dim_Relative|OGT_Y_Dim_Relative },
  138.    { GA_Height          , -14                                   },
  139.  
  140.    { OGTSL_UseNumPad    , TRUE                                  },
  141.    { TAG_DONE                                                   }
  142. };
  143.  
  144. struct OGT_ObjectSettings ListOfObjects[] =
  145. {
  146.    { Class_AslReq  , Object1Desc, Object1Post, OGT_NOOBJECT, OGT_NOOBJECT },
  147.    { Class_Scroller, Object2Desc, NULL       , OGT_NOOBJECT, OGT_NOOBJECT },
  148.    { Class_Scroller, Object3Desc, NULL       , OGT_NOOBJECT, OGT_NOOBJECT },
  149.    { Class_Showlist, Object4Desc, NULL       , OGT_NOOBJECT, OGT_NOOBJECT },
  150.    { NULL                                                                 },
  151. };
  152.  
  153.  
  154.  
  155. struct TagItem Obj2toObj4[] =    /* SCROLLER_OGT_CLASS to SHOWLIST_OGT_CLASS */
  156. {
  157.    { PGA_Top , OGTSL_VertPos },
  158.    { TAG_DONE                }
  159. };
  160.  
  161.  
  162. struct TagItem Obj3toObj4[] =    /* SCROLLER_OGT_CLASS to SHOWLIST_OGT_CLASS */
  163. {
  164.    { PGA_Top , OGTSL_HoriPos },
  165.    { TAG_DONE                }
  166. };
  167.  
  168.  
  169. struct TagItem Obj4toObj2[] =    /* SHOWLIST_OGT_CLASS to SCROLLER_OGT_CLASS */
  170. {
  171.    { OGTSL_VertPos    , PGA_Top     },
  172.    { OGTSL_VertTotal  , PGA_Total   },
  173.    { OGTSL_VertVisible, PGA_Visible },
  174.    { TAG_DONE                       }
  175. };
  176.  
  177. Tag Obj4toObj2Filter[] =
  178. {
  179.    OGTSL_VertPos    ,
  180.    OGTSL_VertTotal  ,
  181.    OGTSL_VertVisible,
  182.    TAG_DONE
  183. };
  184.  
  185.  
  186. struct TagItem Obj4toObj3[] =    /* SHOWLIST_OGT_CLASS to SCROLLER_OGT_CLASS */
  187. {
  188.    { OGTSL_HoriPos    , PGA_Top     },
  189.    { OGTSL_HoriTotal  , PGA_Total   },
  190.    { OGTSL_HoriVisible, PGA_Visible },
  191.    { TAG_DONE                       }
  192. };
  193.  
  194. Tag Obj4toObj3Filter[] =
  195. {
  196.    OGTSL_HoriPos    ,
  197.    OGTSL_HoriTotal  ,
  198.    OGTSL_HoriVisible,
  199.    TAG_DONE
  200. };
  201.  
  202.  
  203. struct TagItem Obj1toObj4[] =    /* ASLREQ_OGT_CLASS to SHOWLIST_OGT_CLASS */
  204. {
  205.    { OGTAR_FullFileName, OGTSL_FileToLoadByName },
  206.    { TAG_DONE                                   }
  207. };
  208.  
  209. Tag Obj1toObj4Filter[] =
  210. {
  211.    OGTAR_FullFileName,
  212.    TAG_DONE
  213. };
  214.  
  215.  
  216. struct OGT_ObjectLink ListOfLinks[] =
  217. {
  218.    { 3           , 1, Obj4toObj2, Obj4toObj2Filter },
  219.    { 3           , 2, Obj4toObj3, Obj4toObj3Filter },
  220.    { 1           , 3, Obj2toObj4                   },
  221.    { 2           , 3, Obj3toObj4                   },
  222.  
  223.    { 0           , 3, Obj1toObj4, Obj1toObj4Filter },
  224.  
  225.    { OGT_NOOBJECT                                  },
  226. };
  227.  
  228.  
  229. static int cleanup( char *str );
  230.  
  231. int main( void )
  232. {
  233.    if(!OpenOGT()) cleanup( "no objectivegadtools.library!\n" );
  234.  
  235.    if(!(Ra = ReadArgs( ARGS_TEMPLATE, args, NULL ))) return( cleanup( "Can't parse args\n" ) );
  236.  
  237.    if(args[ ARGS_FONT ]) MyAttr.ta_Name  =  (STRPTR )args[ ARGS_FONT ];
  238.    if(args[ ARGS_SIZE ]) MyAttr.ta_YSize = *(ULONG *)args[ ARGS_SIZE ];
  239.  
  240.    if(MyAttr.ta_Name)
  241.    {
  242.       if(!(MyFont = OpenDiskFont( &MyAttr ))) return( cleanup( "Can't open font!!\n" ) );
  243.    }
  244.  
  245.    while(1)
  246.    {
  247.       VInfo = OGT_GetVisualInfo( NULL, OGT_TextFont, (ULONG)MyFont         ,
  248.                                        TAG_MORE    , (ULONG)WindowDescTags );
  249.  
  250.       if(VInfo == NULL) return( cleanup( "Can't open my window.\n" ) );
  251.  
  252.       Object1Post[ 0 ].ti_Data = args[ ARGS_FILE ];
  253.  
  254.       if(!OGT_BuildObjects( VInfo, ListOfObjects, ListOfLinks, &Gads )) return( cleanup( "can't create objects" ) );
  255.  
  256.       Win = OGT_GetWindowPtr( VInfo );
  257.  
  258.       {
  259.          BOOL keeprunning = TRUE;
  260.  
  261.          while(keeprunning)
  262.          {
  263.             struct IntuiMessage *imsg;
  264.  
  265.             Wait( 1L << Win->UserPort->mp_SigBit );
  266.  
  267.             while(keeprunning && (imsg = OGT_GetMsg( VInfo )))
  268.             {
  269.                switch(imsg->Class)
  270.                {
  271.                   case IDCMP_CLOSEWINDOW:
  272.                      keeprunning = FALSE;
  273.                      break;
  274.  
  275.                   case IDCMP_IDCMPUPDATE:
  276.                      if(OGT_GetLastTagData( OGT_ID, 0, imsg->IAddress ) == GADGETID_SHOWLIST) /* SHOWLIST_OGT_CLASS */
  277.                      {
  278.                         STRPTR icon = (APTR)OGT_GetLastTagData( OGT_DroppedIcon, NULL, imsg->IAddress );
  279.  
  280.                         if(icon) SetGadgetAttrs( Gads[ 0 ], Win, NULL, OGTAR_FullFileName, (ULONG)icon, TAG_DONE );
  281.                      }
  282.  
  283.                      break;
  284.                }
  285.  
  286.                OGT_ReplyMsg( imsg );
  287.             }
  288.          }
  289.       }
  290.  
  291.       break;
  292.    }
  293.  
  294.    return( cleanup( NULL ) );
  295. }
  296.  
  297. static int cleanup( char *str )
  298. {
  299.    if(str) Printf( "%s\n", str );
  300.  
  301.    if(Ra    ) FreeArgs          ( Ra     );
  302.    if(Gads  ) FreeVec           ( Gads   );
  303.    if(VInfo ) OGT_FreeVisualInfo( VInfo  );
  304.    if(MyFont) CloseFont         ( MyFont );
  305.  
  306.    CloseOGT();
  307.  
  308.    return( str ? 10 : 0 );
  309. }
  310.